import requests
import re
import pyttsx3
class ttsx(object):
      def __init__(self,rate=-40):
          self.rate = rate
      def sayText(self,str):
          self.engine = pyttsx3.init()
          self.engine.setProperty('rate', 400)
          self.engine.say(str)
          self.engine.runAndWait()
ttx = ttsx()
ttx.__init__(20)
for anum in range(60521074, 605210511):
    for number in range(1, 3):
        print(number.__str__())
        # full_url = "https://www.dahuowen.com/xs/113/113120/62165"+number.__str__()+".html"#315
        full_url = "https://www.suibkk.com/read/213110/66489" + number.__str__()  # 460
        full_url = "https://www.suibkk.com/read/185143/63917" + number.__str__()  # 363
        # ull_url ="https://www.xintianxixs.com"+"/xiaoshuo/94371071/171307173.html"
        full_url = "https://www.suibkk.com/read/381935/" + number.__str__()  # 9076
        # full_url = "http://www.suibkk.com/indexlist/381935/"
        # full_url = "http://www.suibkk.com/fenlei/xuanhuan/1/"
        # full_url = "https://www.zmdy8.com/book/157826/80488284_2.html"#ppp2
        full_url = "https://www.zmdy8.com/book/111780/" + anum.__str__() + "_" + number.__str__() + ".html"  # ppp2
        # full_url = "https://www.jiarenbook.com/novel/BQJRWg/"+anum.__str__()+"_"+number.__str__()+".html"#ppp3
        # full_url = "https://www.fengshengbook.com/book/VQVWAA/"+anum.__str__()+"_"+number.__str__()+".html"#ppp4
        # full_url = "http://www.fengshengbook.com/book/VQVWAA.html"

        bbb = 1
        print_if = 0
        html = requests.get(full_url)
        html.encoding = 'utf-8'
        # html.encoding = 'gbk'
        pattern = re.compile(r'[^\u4e00-\u9fa5]')
        chinese = re.sub(pattern, "", html.text)
        # print(html.text)
        xxxxx = html.text.replace("<br><br>", "\n")
        xxxxx = xxxxx.replace("<br /><br />", "\n")
        xxxxx = xxxxx.replace("<br/><br/>", "\n")
        xxxxx = xxxxx.replace("</p><p>", "\n")
        xxxxx = xxxxx.replace("<p>", "\n")
        xxxxx = xxxxx.replace("<br />　　<br />", "\n")
        xxxxx = xxxxx.replace("<br />", "")
        xxxxx = xxxxx.replace("“", "")
        xxxxx = xxxxx.replace("”", "")
        xxxxx = xxxxx.replace("&nbsp;&nbsp;&nbsp;&nbsp;", "\t")
        # print(xxxxx)
        # start = xxxxx.find("id=\"content\"")
        # end = xxxxx.find("nofollow")
        start = xxxxx.find("booktxt")  # ppp2
        end = xxxxx.find("content_2")  # ppp2
        # start = xxxxx.find("class=\"content\"")#ppp3
        # end = xxxxx.find("row justify-content-between")#ppp3
        zzzz = xxxxx[start + 16:end - 55]
        zzzz = zzzz.replace("<", "")
        zzzz = zzzz.replace("", "")
        if print_if:
            print(zzzz)
        xdf = 0
        try:
            xdf = html.text.index(">下一页")
        except:
            try:
                xdf = html.text.index(">下一章")
            except:
                print("next")
        print(html.text[xdf - 50:xdf])
        if bbb:
            ttx.sayText(zzzz)




